home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Appearance SDK 1.0.4 / Appearance Sample Code / Source / SliderPane.cp < prev    next >
Encoding:
Text File  |  1999-07-16  |  7.7 KB  |  262 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        SliderPane.cp
  3.  
  4.     Contains:    Class to drive our example slider pane.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <1>     9/11/97    edv        First checked in.
  25. */
  26.  
  27. #include <TextUtils.h>
  28. #include "SliderPane.h"
  29. #include "Appearance.h"
  30. #include "UDialogUtils.h"
  31. #include "AppearanceHelpers.h"
  32. #include "ColorPenState.h"
  33. #include "Offscreen.h"
  34.  
  35. enum
  36. {
  37.     kHorizontalSlider1        = 1,
  38.     kHorizontalSlider2        = 2,
  39.     kHorizontalSlider3        = 3,
  40.     kVerticalSlider1        = 4,
  41.     kVerticalSlider2        = 5,
  42.     kVerticalSlider3        = 6,
  43.     kLiveFeedbackCheckBox    = 7,
  44.     kStaticText                = 8,
  45.     kUserPane                = 9
  46. };
  47.  
  48. #define MIN( a, b )        ( ( (a) < (b) ) ? (a) : (b) )
  49. #define MAX( a, b )        ( ( (a) > (b) ) ? (a) : (b) )
  50.  
  51. ControlActionUPP    SliderPane::fSliderProc = NewControlActionProc( SliderPane::SliderFeedbackProc );
  52. ControlUserPaneDrawUPP    SliderPane::fDrawProc = NewControlActionProc( SliderPane::DrawPictureProc );
  53.  
  54. SliderPane::SliderPane( DialogPtr dialog, SInt16 items ) : MegaPane( dialog, items )
  55. {
  56.     AppendDialogItemList( dialog, 6002, overlayDITL );
  57.     
  58.     GetDialogItemAsControl( dialog, items + kHorizontalSlider1, &fHorizontalSlider1 );
  59.     GetDialogItemAsControl( dialog, items + kHorizontalSlider2, &fHorizontalSlider2 );
  60.     GetDialogItemAsControl( dialog, items + kHorizontalSlider3, &fHorizontalSlider3 );
  61.     GetDialogItemAsControl( dialog, items + kVerticalSlider1, &fVerticalSlider1 );
  62.     GetDialogItemAsControl( dialog, items + kVerticalSlider2, &fVerticalSlider2 );
  63.     GetDialogItemAsControl( dialog, items + kVerticalSlider3, &fVerticalSlider3 );
  64.     
  65.     SetControlReference( fHorizontalSlider1, (long)this );
  66.     SetControlReference( fHorizontalSlider2, (long)this );
  67.     SetControlReference( fHorizontalSlider3, (long)this );
  68.     SetControlReference( fVerticalSlider1, (long)this );
  69.     SetControlReference( fVerticalSlider2, (long)this );
  70.     SetControlReference( fVerticalSlider3, (long)this );
  71.     
  72.     GetDialogItemAsControl( dialog, items + kUserPane, &fUserPane );
  73.     SetControlReference( fUserPane, (long)this );
  74.     SetControlData( fUserPane, 0, kControlUserPaneDrawProcTag, sizeof( fDrawProc ), (Ptr)&fDrawProc );
  75.  
  76.     fPicture = GetPicture( 6002 );
  77.     fPictWidth = (**fPicture).picFrame.right - (**fPicture).picFrame.left;
  78.     fPictHeight = (**fPicture).picFrame.bottom - (**fPicture).picFrame.top;
  79. }
  80.  
  81. SliderPane::~SliderPane()
  82. {
  83.     ShortenDITL( fDialog, CountDITL( fDialog ) - fOrigItems );
  84. }
  85.  
  86. void
  87. SliderPane::ItemHit( SInt16 item )
  88. {
  89.     SInt16            localItem;
  90.     ControlHandle    control;
  91.     
  92.     localItem = item - fOrigItems;
  93.     
  94.     switch ( localItem )
  95.     {
  96.         case kHorizontalSlider1:
  97.         case kHorizontalSlider2:
  98.         case kHorizontalSlider3:
  99.         case kVerticalSlider1:
  100.         case kVerticalSlider2:
  101.         case kVerticalSlider3:
  102.             if ( UDialogUtils::GetDialogItemValue( fDialog, fOrigItems + kLiveFeedbackCheckBox ) == 0 )
  103.             {
  104.                 GetDialogItemAsControl( fDialog, item, &control );
  105.                 SliderFeedbackProc( control, kControlIndicatorPart );
  106.             }
  107.             break;
  108.             
  109.         case kLiveFeedbackCheckBox:
  110.             UDialogUtils::ToggleCheckBox( fDialog, item );
  111.             GetDialogItemAsControl( fDialog, item, &control );
  112.             if ( GetControlValue( control ) == 0 )
  113.             {
  114.                 SetControlAction( fHorizontalSlider1, nil );
  115.                 SetControlAction( fHorizontalSlider2, nil );
  116.                 SetControlAction( fHorizontalSlider3, nil );
  117.                 SetControlAction( fVerticalSlider1, nil );
  118.                 SetControlAction( fVerticalSlider2, nil );
  119.                 SetControlAction( fVerticalSlider3, nil );
  120.             }
  121.             else
  122.             {
  123.                 SetControlAction( fHorizontalSlider1, fSliderProc );
  124.                 SetControlAction( fHorizontalSlider2, fSliderProc );
  125.                 SetControlAction( fHorizontalSlider3, fSliderProc );
  126.                 SetControlAction( fVerticalSlider1, fSliderProc );
  127.                 SetControlAction( fVerticalSlider2, fSliderProc );
  128.                 SetControlAction( fVerticalSlider3, fSliderProc );
  129.             }
  130.             break;
  131.     }
  132. }
  133.  
  134. pascal void
  135. SliderPane::SliderFeedbackProc( ControlHandle control, SInt16 part )
  136. {
  137.     #pragma unused( part )
  138.     
  139.     ControlHandle        text;
  140.     Str255                valueText;
  141.     SliderPane*            pane;
  142.     SInt16                startValue;
  143.  
  144.     startValue = GetControlValue( control );
  145.     
  146.     pane = (SliderPane*)GetControlReference( control );
  147.  
  148.     GetDialogItemAsControl( (**control).contrlOwner, kStaticText + pane->fOrigItems, &text );
  149.     NumToString( GetControlValue( control ), valueText );
  150.     SetStaticTextText( text, valueText, true );
  151.  
  152.     if ( control == pane->fHorizontalSlider1 )
  153.     {
  154.         SetControlValue( pane->fHorizontalSlider2, startValue );
  155.         SetControlValue( pane->fHorizontalSlider3, startValue );
  156.         SetControlValue( pane->fVerticalSlider1, startValue );
  157.         SetControlValue( pane->fVerticalSlider2, startValue );
  158.         SetControlValue( pane->fVerticalSlider3, startValue );
  159.     }
  160.     else if ( control == pane->fHorizontalSlider2 )
  161.     {
  162.         SetControlValue( pane->fHorizontalSlider1, startValue );
  163.         SetControlValue( pane->fHorizontalSlider3, startValue );
  164.         SetControlValue( pane->fVerticalSlider1, startValue );
  165.         SetControlValue( pane->fVerticalSlider2, startValue );
  166.         SetControlValue( pane->fVerticalSlider3, startValue );
  167.     }
  168.     else if ( control == pane->fHorizontalSlider3 )
  169.     {
  170.         SetControlValue( pane->fHorizontalSlider1, startValue );
  171.         SetControlValue( pane->fHorizontalSlider2, startValue );
  172.         SetControlValue( pane->fVerticalSlider1, startValue );
  173.         SetControlValue( pane->fVerticalSlider2, startValue );
  174.         SetControlValue( pane->fVerticalSlider3, startValue );
  175.     }
  176.     else if ( control == pane->fVerticalSlider1 )
  177.     {
  178.         SetControlValue( pane->fHorizontalSlider1, startValue );
  179.         SetControlValue( pane->fHorizontalSlider2, startValue );
  180.         SetControlValue( pane->fHorizontalSlider3, startValue );
  181.         SetControlValue( pane->fVerticalSlider2, startValue );
  182.         SetControlValue( pane->fVerticalSlider3, startValue );
  183.     }
  184.     else if ( control == pane->fVerticalSlider2 )
  185.     {
  186.         SetControlValue( pane->fHorizontalSlider1, startValue );
  187.         SetControlValue( pane->fHorizontalSlider2, startValue );
  188.         SetControlValue( pane->fHorizontalSlider3, startValue );
  189.         SetControlValue( pane->fVerticalSlider1, startValue );
  190.         SetControlValue( pane->fVerticalSlider3, startValue );
  191.     }
  192.     else if ( control == pane->fVerticalSlider3 )
  193.     {
  194.         SetControlValue( pane->fHorizontalSlider1, startValue );
  195.         SetControlValue( pane->fHorizontalSlider2, startValue );
  196.         SetControlValue( pane->fHorizontalSlider3, startValue );
  197.         SetControlValue( pane->fVerticalSlider1, startValue );
  198.         SetControlValue( pane->fVerticalSlider2, startValue );
  199.     }
  200.     DrawPictureProc( pane->fUserPane, 0 );
  201. }
  202.  
  203. pascal void
  204. SliderPane::DrawPictureProc( ControlHandle control, SInt16 part )
  205. {
  206.     #pragma unused( part )
  207.     
  208.     Rect            bounds;
  209.     RgnHandle        saveClip;
  210.     SliderPane*        pane;
  211.     CGrafPtr        currPort;
  212.     GDHandle        currDevice;
  213.     Rect            globalBounds;
  214.     ColorPenState    state;
  215.     Offscreen        mainBuffer;
  216.     Offscreen        pictBuffer;
  217.     RGBColor        alphaColor;
  218.     SInt16            value;
  219.     SInt16            component;
  220.     
  221.     GetColorAndPenState( &state );
  222.     
  223.     pane = (SliderPane*)GetControlReference( control );
  224.     bounds = (**control).contrlRect;
  225.     
  226.     FrameRect( &bounds );
  227.     InsetRect( &bounds, 1, 1 );
  228.     
  229.     saveClip = NewRgn();
  230.     GetClip( saveClip );
  231.     
  232.     ClipRect( &bounds );
  233.  
  234.     bounds.bottom = bounds.top + pane->fPictHeight;
  235.     bounds.right = bounds.left + pane->fPictWidth;
  236.     
  237.     globalBounds = bounds;
  238.     LocalToGlobal( &topLeft( globalBounds ) );
  239.     LocalToGlobal( &botRight( globalBounds ) );
  240.     
  241.     GetGWorld( &currPort, &currDevice );
  242.  
  243.     value = GetControlValue( pane->fVerticalSlider1 );
  244.     component = value << 8;
  245.     component |= value;
  246.     
  247.     alphaColor.red = alphaColor.green = alphaColor.blue = component;
  248.  
  249.     mainBuffer.StartDrawing( bounds );
  250.     pictBuffer.StartDrawing( bounds );
  251.     
  252.     DrawPicture( pane->fPicture, &bounds );
  253.     
  254.     pictBuffer.EndDrawingAndBlend( alphaColor );
  255.     mainBuffer.EndDrawing();
  256.     
  257.     SetColorAndPenState( &state );
  258.     
  259.     SetClip( saveClip );
  260.     DisposeRgn( saveClip );
  261. }
  262.